package com.education.service.impl;

import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.education.dao.StudentDao;
import com.education.model.StudentModel;
import com.education.service.IStuMoneyService;

/**
 * 学生缴费业务层数据
 * @author 李梦鸽
 *
 */
@Service
public class StuMoneyServiceImpl implements IStuMoneyService{


	/**
	 * 日志记录类
	 */
	private static Logger MYLOGGER = LogManager.getLogger(StuIndexServiceImpl.class);

	/**
	 * 学生缴费状态依赖注入StudentDao接口
	 */
	@Autowired
	private StudentDao studentDao;
	
	
	/**
	 * 查询学生的缴费状态
	 * 
	 * */
	@Override
	public List<StudentModel> queryStuMoneyById(Integer studentId) throws Exception {
		
		List<StudentModel> stuMoneyList = studentDao.getStuMoney(studentId);
		MYLOGGER.info("查询学生缴费状态----"+stuMoneyList);
		for(StudentModel stuMd : stuMoneyList){
			MYLOGGER.info("判断缴费状态：----");
			double firstMoney = stuMd.getFirstMoney();
			double secondMoney = stuMd.getSecondMoney();
			if(firstMoney==0 ){
				stuMd.setFirstMoneyState("未交费");
			}else{
				stuMd.setFirstMoneyState("已缴费");
			}
			if(secondMoney==0){
				stuMd.setSecondMoneyState("未交费");
			}else{
				stuMd.setSecondMoneyState("已缴费");
			}
		}

		return stuMoneyList;
	}

	/**
	 * 根据身份证缴费
	 * */
	@Override
	public StudentModel payMoney(String studentIdcard) throws Exception {
		StudentModel payMoney=studentDao.payMoney(studentIdcard);
		return payMoney;
	}
	
	/**
	 * 更新学生缴费信息
	 * @throws Exception 
	 * */
	@Override
	public int updateMoney(StudentModel studentModel) throws Exception {
		studentDao.updateMoney(studentModel);
		return 0;
	}


}
